<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$roomsnum=pdo_count('jy_weishop_live_room',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$daytime));
	if(intval($return['pluginset']['openrooms_num']) && $roomsnum>=intval($return['pluginset']['openrooms_num'])){
		exi('您今天已经创建'.$roomsnum.'间了，不能再创建了，明天再来吧！','error');
	}
	$return['member']=model('core/member')->detail($_SESSION['uid'],array('sex','credit1','credit2','mobile','avatar','nickname'));
	$id=$_RQ['id'];
	if($id){
		$item=pdo_get('jy_weishop_live_room',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['livetime'] =$item['livetime']?date('Y-m-d H:i',$item['livetime']):'';
	}else{
		$item=array();
		$item['livetime'] =$item['livetime']?:date('Y-m-d H:i');
	}
	$return['item']=$item;
	$return['groups']=pdo_getall('jy_weishop_live_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['covertype']=array('0'=>'自动抓取直播封面','1'=>'自定义封面');
	$return['types']=array('0'=>'第三方平台','1'=>'智能摄像头','2'=>'行业解决方案','3'=>'企业微信');
	$return['type0']=array('inke'=>'映客直播','douyu'=>'斗鱼直播','douyin'=>'抖音直播','huajiao'=>'花椒直播','yizhibo'=>'一直播');		
	$return['type1']=array('qlive'=>'青果直播','ys7'=>'萤石直播');
	$return['type2']=array('tencentcloud'=>'腾讯云直播','alicloud'=>'阿里云直播','other'=>'其他直播');
	exi($return);
}
if($_RQ['op']=='post'){
		$post=get_postdata();
		$data=array_fields(array('islikered','hb_rate','allred','minhb','maxhb','mid','image','title','type','livetime','livept','notice','status','share_image','share_desc','share_title','group_id','url','isrecommend','ishot','paixu','video','pushurl','isscreen','goodsid','iscoupon','couponid','invitation_id','covertype','cover','roomewm'),$post);
		if(!$data['title']){
			exi('请填写直播间名称！','error');
		}
		if(mb_strlen($data['title'])<3 || mb_strlen($data['title'])>17){
			exi('直播间名字，最短3个汉字，最长17个汉字！','error');
		}
		if(!$data['image']){
			exi('请填写封面图！','error');
		}
		if(!$data['livetime']){
			exi('请填写开始直播时间！','error');
		}
		$data['livetime'] = intval(strtotime($data['livetime']))?:time()+1*3600;
		$id=intval($post['id']);
		if($id){
			pdo_update('jy_weishop_live_room',$data,array('id'=>$id));
			exi('编辑成功！','','jy_h5live/myroom/');
		}else{
			$data['createtime']=TIMESTAMP;
			$data['uniacid']=$_SESSION['uniacid'];
			$data['mid']=$_SESSION['uid'];
			pdo_insert('jy_weishop_live_room',$data);
		}
		exi('创建成功！','','jy_h5live/myroom/');
}
if($_RQ['op']=='getvideo'){
	$post=get_postdata();
	$url = trim($post['url']);
	$type = trim($post['livept'])?:'auto';
	if (empty($url)) {
		exi('请输入直播地址','error');
	}
	if (!strexists($url, 'http://') && !strexists($url, 'https://')) {
		exi('直播地址请以http://或https://开头','error');
	}
	$result = $this->model('model')->getLiveInfo($url, $type);
	if (is_error($result)) {
		exi($result['message'],'error');
	}		
	exi($result);
}